package com.itheima.attendance.controller;

import com.itheima.attendance.pojo.AttendanceConfig;
import com.itheima.attendance.service.ConfigService;
import com.itheima.common.controller.BaseController;
import com.itheima.common.entity.Result;
import com.itheima.common.entity.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author qiankaofei
 * @version 1.0
 * @date 2020/12/10 21:41
 */
@CrossOrigin
@RequestMapping("/cfg")
@RestController
public class ConfigController extends BaseController {

    @Autowired
    private ConfigService configService;

    /**
     *根据企业id和部门id查询考情设置
     */
    @PostMapping("/atte/item")
    public Result findAttenByDeptementIdAndCompanyId(@RequestParam("depetmentId") String depetmentId){
        return new Result(ResultCode.SUCCESS,configService.findAttenByDeptementIdAndCompanyId(depetmentId,this.companyId));
    }

    /**
     * 设置企业部门的的考勤
     */
    @PutMapping("/atte")
    public Result setAtten(@RequestBody AttendanceConfig attendanceConfig){
        attendanceConfig.setCompanyId(this.companyId);
        return configService.setAttenByCompanyIdAndDeptementId(attendanceConfig)>0?new Result(ResultCode.SUCCESS):new Result(ResultCode.FAIL);
    }

}
